<template>
    <div class="teachMaterialDBManage">
      <el-form :model="searchForm" :rules="rules" ref="searchForm" label-width="0px">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item prop="">
              <el-input v-model="searchForm.courseNameCN" placeholder="请输入课程名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="">
              <el-input v-model="searchForm.textbookName" placeholder="请输入教材名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="grid-content"></div>
          </el-col>
          <el-col :span="6" class="overflow-clear">
            <el-button type="primary" @click="submitForm('searchForm')" class="float-right">立即搜索</el-button>
          </el-col>
        </el-row>
      </el-form>
      <hr>
      <div class="overflow-clear">
        <!--<h1 class="float-left">教材库管理</h1>-->
        <div class="float-left table-title-before">
          教材库管理
        </div>
        <el-button-group class="float-right" style="margin-bottom: 4px;">
          <el-button type="primary"><router-link to="/NewTeachMaterial">新增</router-link></el-button>
          <el-button type="primary">打印</el-button>
        </el-button-group>
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          prop="materialId"
          label="编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="materialName"
          label="教材名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="press"
          label="出版社"
          width="180">
        </el-table-column>
        <el-table-column
          prop="author"
          label="作者"
          width="180">
        </el-table-column>
        <el-table-column
          prop="isbn"
          label="ISBN"
          width="180">
        </el-table-column>
        <el-table-column
          prop="price"
          label="单价"
          width="180">
        </el-table-column>
        <el-table-column
          prop="courseName"
          label="课程名称"
          width="180">
        </el-table-column>

        <el-table-column
          label="操作">
          <template scope="scope">
            <router-link to="/NewTeachMaterial"><i class="el-icon-edit"></i></router-link>
            <router-link to="" @click.native.prevent="deleteRow(scope.$index, tableData)"><i class="el-icon-delete"></i></router-link>
          </template>
        </el-table-column>
      </el-table>

      <div class="paging">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[100, 200, 300, 400]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="400">
        </el-pagination>
      </div>
    </div>
</template>
<style>
    .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
</style>
<script>
    export default{
        name : 'teachMaterialDBManage',
        data(){
            return{
                tableData:[],
                searchForm:{
                    courseNameCN: '',
                    textbookName: ''
                }
            }
        },
        components:{
        },
        mounted:function(){
            this.$nextTick(function(){
              this.res();
            })
        },
        methods:{
            res:function(){
                // GET /someUrl
                this.$http.get('/static/teachMaterial.json').then(response => {
                  // get body data
                  for (const element of response.body.teachMaterial){
                      //push to tableData[]
                      this.tableData.push(element);
                  }
                }, response => {
                  // error callback
                  alert("no file page");
                });
            },
            deleteRow:function(index, rows) {
              rows.splice(index, 1);
            },
            submitForm(formName) {
              this.$refs[formName].validate((valid) => {
                if (valid) {
                  alert('submit!');
                } else {
                  console.log('error submit!!');
                  return false;
                }
              });
            }
        }
    }
</script>
